//
// Created by 张祎鹤严 on 2022/11/28.
//

#ifndef _PID_H
#define _PID_H
#include "math.h"
typedef struct
{
    float  Ref;   			// 目标速度
    float  Fdb;   			// 反馈速度
    float  Err;				// 误差

    float  Kp;				// Parameter: Proportional gain
    float  Ki;			    // Parameter: Integral gain
    float  Kd; 		        // Parameter: Derivative gain

    float  Ap;
    float  Bp;
    float  Cp;
    float  Ai;
    float  Ci;
    float  Ad;
    float  Bd;
    float  Cd;
    float  Kl;
    float  ErrRef;


    float  Up;				// Variable: Proportional output
    float  Ui;				// Variable: Integral output
    float  Ud;				// Variable: Derivative output
    float  OutPreSat; 		// Variable: Pre-saturated output
    float  OutMax;		    // Parameter: Maximum output
    float  OutMin;	    	// Parameter: Minimum output
    float  Out;   			// Output: PID output
    float  SatErr;			// Variable: Saturated difference
    float  Kc;		     	// Parameter: Integral correction gain
    float  Up1;		   	    // History: Previous proportional output
    void  (*calc)();	  	// Pointer to calculation function
    void  (*clear)();
    void  (*calc2)();
} PID;

void PidCalc(PID *v);
void PidClear(PID *v);
void PidCalc2(PID *v);
#endif
